<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('课程章节列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input type="hidden" name="lessonId" id="lessonId" th:value="${lesson.id}"/>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="add()" shiro:hasPermission="lesson:course:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary " onclick="batchadd()" shiro:hasPermission="lesson:course:edit">
                    <i class="fa fa-edit"></i> 批量上传
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="lesson:course:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="lesson:course:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('lesson:course:edit')}]];
        var removeFlag = [[${@permission.hasPermi('lesson:course:remove')}]];
        var prefix = ctx + "lesson/course";
        var mediaPrefix = ctx + "lesson/media";

        $(function() {
            var options = {
                sortName: "sort",
     		    sortOrder: "asc",
                url: prefix + "/list",
                createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "课程章节",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : 'id',
                    visible: false
                },
                {
                    field : 'name', 
                    title : '章节名称'
                },
                {
                    field : 'resType', 
                    title : '资源类型',
                    formatter: function(value, row, index) {
                       return value == 1?'视频': '音频';
                    }
                },
                {
                    field : 'vodId',
                    title : 'vodId'
                },
                {
                    field : 'sort', 
                    title : '排序'
                },
                {
                    field : 'free',
                    title : '是否免费试看/听',
                    formatter: function(value, row, index) {
                    	if(value == 1){
                      	   return '<i class=\"fa fa-toggle-on text-info fa-2x\" )"></i>'
                        }else{
                      	   return '<i class=\"fa fa-toggle-off text-info fa-2x\" )"></i>'
                        }
                    }
                },
                {
                    field : 'createdTime', 
                    title : '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        if(row.vodId){
                           actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="play(\'' + row.vodId + '\')"><i class="fa fa-edit"></i>播放</a> ');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function add() {
		    var lessonId = $("#lessonId").val();
		    $.operate.add(lessonId);
		}

        function batchadd() {
		    var lessonId = $("#lessonId").val();
		    var url = prefix + "/batchadd/" + lessonId;
		    $.modal.openFull("批量添加课程", url);
		}

		function play(vodId) {
		    var url = mediaPrefix + "/play/" + vodId;
		    $.modal.openTab("播放视频", url);
		}

    </script>
</body>
</html>